﻿using System;
using Netbits.Common.Network;

namespace Netbits.TelnetServer
{
	public class NetbitsTelnetServer : TcpServer<NetbitsTelnetClientSession>
	{
		#region Private Variables

		Folder _StaticFolder;
		Func<string, string, ITelnetAuthentication> _Authenticate;
		string _WelcomeMessage;

		#endregion

		#region Constructor

		public NetbitsTelnetServer( string Name_ ) : base( Name_ )
		{
			_StaticFolder = new Folder( null, "static-main" );
		}

		public NetbitsTelnetServer( string Name_, BindEndPoint EndPoint_ ) : base( Name_, EndPoint_ )
		{
			_StaticFolder = new Folder( null, "static-main" );
		}

		#endregion

		#region Public Properties

		/// <summary>
		/// Get the static-folder. 
		/// This folder and all sub-folders with commands are available for all clients.
		/// </summary>
		public Folder Folder
		{
			get
			{
				return _StaticFolder;
			}
		}

		/// <summary>
		/// Get or set the delegate for telnet-authentication.
		/// </summary>
		public Func<string, string, ITelnetAuthentication> Authenticate
		{
			get
			{
				return _Authenticate;
			}
			set
			{
				_Authenticate = value;
			}
		}

		/// <summary>
		/// Get or set the welcome message for all telnet-clients
		/// </summary>
		public string WelcomeMessage
		{
			get
			{
				return _WelcomeMessage;
			}
			set
			{
				_WelcomeMessage = value;
			}
		}

		#endregion

		#region Overrides

		protected override void __Connected( NetbitsTelnetClientSession Session_ )
		{
			Session_.SetServer( this );			
		} 

		#endregion
	}
}
